//package com.coldchain.order.service.impl;
//
//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
//import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
//import com.coldchain.common.vo.OrderCountResultVo;
//import com.coldchain.common.feign.ExpressionFeign;
//import com.coldchain.message.MessageUtils;
//import com.coldchain.order.entiy.*;
//import com.coldchain.order.mapper.CreditOrderMapper;
//import com.coldchain.order.mapper.OrderMapper;
//import com.coldchain.order.service.IBizDispatchingOrderServicecoo;
//import com.coldchain.order.service.IBizReceiverGoodsService;
//import com.coldchain.order.service.IBizReceiverPersonService;
//import com.coldchain.order.service.IOrderService;
//import com.coldchain.order.vo.AppPerson;
//import com.coldchain.common.vo.OrderVo;
//import BusinessException;
//import ObjectRestResponse;
//import FunctionUtils;
//import ValidateUtil;
//import com.fangliai.core.base.service.impl.BaseServiceImpl;
//import com.fangliai.core.entitiy.BaseSearch;
//import com.fangliai.core.entitiy.PageResponse;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//import org.springframework.transaction.annotation.Transactional;
//
//import java.math.BigDecimal;
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//
//
///**
// * <p>
// * 订单 服务实现类
// * </p>
// *
// * @author fangliai
// * @since 2018-09-11
// */
//@Service
//public class OrderServiceImpl extends BaseServiceImpl<OrderMapper,Order> implements IOrderService {
//	@Autowired
//	private IBizReceiverGoodsService bizReceiverGoodsService;
//	@Autowired
//	private IBizReceiverPersonService bizReceiverPersonService;
//	@Autowired
//	private IBizDispatchingOrderServicecoo bizDispatchingOrderService;
//	@Autowired
//	private OrderMapper orderMapper;
//	@Autowired
//	private ExpressionFeign expressionFeign;
//	@Autowired
//	private MessageUtils messageUtils;
//	@Autowired
//	private CreditOrderMapper creditOrderMapper;
//
//	@SuppressWarnings("unchecked")
//	@Transactional
//	@Override
//	public ObjectRestResponse<String> handleBizOrder(OrderVo ordervo){
//		Order order = new Order();
//		order.setCompanyId(ordervo.getUser());
//		order.setContent(ordervo.getRemark());
//		order.setTime(ordervo.getTime());
//		order.setOrderId(ordervo.getOrderid());
//		order.setBizType(1);
//		order.setTitle("商品");
//		order.setContent(ordervo.getRemark());
//		order.setPriceUnit("RMB");
//		order.setChannel(1);
//		BizDispatchingOrdercao biz = new BizDispatchingOrdercao();
//		biz.setBizId(ordervo.getBizid());
//		biz.setOrderId(order.getOrderId());
//		biz.setCarTypeId(ordervo.getTypecar());
//		biz.setCarOcMax(ordervo.getCarOcMax());
//		biz.setCarOcMin(ordervo.getCarOcMin());
//		biz.setShipAddress(ordervo.getShipAddress());
//		biz.setLongitude(ordervo.getLongitude());
//		biz.setLatitude(ordervo.getLatitude());
//		biz.setShipContact(ordervo.getShipContact());
//		biz.setShipPhone(ordervo.getShipPhone());
//		biz.setInstancyContact(ordervo.getInstancyContact());
//		biz.setInstancyPhone(ordervo.getInstancyPhone());
//		biz.setOrderType(ordervo.getOrderType());
//		biz.setOrderKm(ordervo.getOrderkm());
//		biz.setPredictKm(ordervo.getOrderkm());
//		biz.setGeohash(ordervo.getGeohash());
//		biz.setCarTypeName(ordervo.getCarTypeName());
//		biz.setPriceUnit("RMB");
//
//		ObjectRestResponse<OrderCountResultVo> orderPrice = expressionFeign.getOrderPrice(biz.getOrderKm().intValue(),ordervo.getReceiver().size()-1,ordervo.getGeohash(),ordervo.getTypecar(),ordervo.getCardeliver());
//		if(orderPrice.getStatus()!=200){
//			throw new BusinessException(orderPrice.getMessage());
//		}
//		OrderCountResultVo orderCountResult = orderPrice.getData();
//		order.setPaymoney(new BigDecimal(orderCountResult.getOrderPrice()));
//
//		biz.setInitiatePrice(new BigDecimal(orderCountResult.getUsePrice()));
//		biz.setTaxes(BigDecimal.ZERO);
//		biz.setExceedPrice(orderCountResult.getExceedKm()*orderCountResult.getExceedPrice());
//		biz.setTotlaPrice(new BigDecimal(orderCountResult.getOrderPrice()));
//		biz.setAmount(biz.getTotlaPrice());
//		biz.setDiscount(orderCountResult.getDiscounts());
//
//		boolean falg = false;
//		if(super.save(order)){
//			if(this.bizDispatchingOrderService.save(biz)){
//				List<BizReceiverPerson> receiver = ordervo.getReceiver();
//				if(this.bizReceiverPersonService.saveBatch(receiver)){
//					if(this.bizReceiverGoodsService.saveBatch(ordervo.getGoods())){
//						falg = true;
//					}
//				}
//			}
//		}
//		if(falg){
//			return FunctionUtils.getSuccessRest("下单成功",biz.getBizId());
//		}
//		throw new BusinessException("下单失败");
//	}
//
//	@Override
//	public PageResponse<Order> search(BaseSearch<Order> search) {
//		Page<Order> page=search.initPage();
//		List<Order> result = orderMapper.getList(page, search.initWrapper());
//		page.setRecords(result);
//		return new PageResponse<Order>(page) ;
//
//	}
//
//	@Override
//	public ObjectRestResponse<String> cysMoneySearch(OrderSearch orderSearch) {
//		BigDecimal money = this.orderMapper.cysMoney(orderSearch);
//		return new ObjectRestResponse<String>(money==null?"0":money.toString());
//	}
//
//	@Override
//	public Integer count(BaseSearch<Order> baseSearch) {
//		return this.orderMapper.count(baseSearch.initWrapper());
//	}
//
//	@Override
//	public List<Order> searchForList(BaseSearch<Order> search) {
//		List<Order> list = this.orderMapper.searchForList(search.initWrapper());
//		return list==null?new ArrayList<Order>():list;
//	}
//
//	@Override
//	public List<BizReceiverPerson> queryByIdAddr(String bizId, String orderId) {
//		if(!ValidateUtil.stringEmpty(bizId)||!ValidateUtil.stringEmpty(orderId)){
//			return new ArrayList<>();
//		}
//		QueryWrapper<BizReceiverPerson> queryWrapper = new QueryWrapper<>();
//		if(ValidateUtil.stringEmpty(bizId)){
//			queryWrapper.eq("biz_id", bizId);
//		}
//		if(ValidateUtil.stringEmpty(orderId)){
//			queryWrapper.eq("order_id", orderId);
//		}
//		queryWrapper.orderByAsc("sort");
//		return this.bizReceiverPersonService.list(queryWrapper);
//	}
//
//	@Override
//	public ObjectRestResponse<Object> addressUrl(String bizId, String orderId) {
//		if(!ValidateUtil.stringEmpty(bizId)&&!ValidateUtil.stringEmpty(orderId)){
//			return FunctionUtils.getFailRest("没有找到记录");
//		}
//		QueryWrapper<BizDispatchingOrdercao> queryWrapper = new QueryWrapper<>();
//		if(ValidateUtil.stringEmpty(bizId)){
//			queryWrapper.eq("biz_id", bizId);
//		}
//		if(ValidateUtil.stringEmpty(orderId)){
//			queryWrapper.eq("order_id", orderId);
//		}
//		BizDispatchingOrdercao bizorder = this.bizDispatchingOrderService.getOne(queryWrapper);
//		if(ValidateUtil.Objectempty(bizorder)||ValidateUtil.isEquals(0, bizorder.getStatus())){
//			FunctionUtils.getFailRest("没有找到记录或未支付");
//		}
//		HashMap<String,Object> map = new HashMap<>();
//		List<AppPerson> appPersonAll = new ArrayList<>();
//		AppPerson appPerson = new AppPerson();
//		appPerson.setBizId(bizorder.getBizId());
//		appPerson.setOrderId(bizorder.getOrderId());
//		appPerson.setLatitude(bizorder.getLatitude()+"");
//		appPerson.setLongitude(bizorder.getLongitude()+"");
//		appPerson.setName(bizorder.getShipContact());
//		appPerson.setConent(bizorder.getShipAddress());
//		appPerson.setSort(0);
//		appPerson.setTitle(bizorder.getShipAddress());
//		appPerson.setPhone(bizorder.getShipPhone());
//		appPersonAll.add(appPerson);
//		appPerson.setAddrid(0L);
//		QueryWrapper<BizReceiverPerson> wrapper = new QueryWrapper<>();
//		wrapper.eq("biz_id", bizorder.getBizId());
//		wrapper.orderByAsc("sort");
//		List<BizReceiverPerson> personAll = this.bizReceiverPersonService.list(wrapper);
//		boolean sortfalg = false;
//		for(int x  =0 ;x < personAll.size();x++){
//			BizReceiverPerson person = personAll.get(x);
//			appPerson = new AppPerson();
//			appPerson.setBizId(person.getBizId());
//			appPerson.setOrderId(person.getOrderId());
//			appPerson.setLatitude(person.getLatitude()+"");
//			appPerson.setLongitude(person.getLongitude()+"");
//			appPerson.setName(person.getReceiverName());
//			appPerson.setConent(person.getAddrdetail());
//			appPerson.setSort(person.getSort());
//			appPerson.setTitle(person.getLocation());
//			appPerson.setPhone(person.getReceiverPhone());
//			appPerson.setAddrid(person.getId());
//			QueryWrapper<BizReceiverGoods> goods = new QueryWrapper<>();
//			goods.eq("receiverid", person.getPersonId());
//			appPerson.setGoods(this.bizReceiverGoodsService.list(goods));
//			appPersonAll.add(appPerson);
//			if(!sortfalg&&ValidateUtil.isEquals(person.getStatus(),1)){
//				map.put("sort",appPerson.getSort());
//				sortfalg = true;
//			}
//			appPersonAll.add(appPerson);
//		}
//		map.put("persons", appPersonAll);
//		/*if(ValidateUtil.isEquals(bizorder.getStatus(),2)){
//			map.put("longitude", bizorder.getLongitude());
//			map.put("latitude", bizorder.getLatitude());
//			QueryWrapper<BizReceiverGoods> goods = new QueryWrapper<>();
//			goods.eq("biz_id", bizorder.getBizId());
//			map.put("goods", this.bizReceiverGoodsService.list(goods));
//			map.put("address",bizorder.getShipAddress());
//			map.put("phone", bizorder.getShipPhone());
//			map.put("name", bizorder.getShipContact());
//		}else if(ValidateUtil.isEquals(bizorder.getStatus(),3)){
//			QueryWrapper<BizReceiverPerson> wrapper = new QueryWrapper<>();
//			wrapper.eq("biz_id", bizorder.getBizId());
//			wrapper.eq("static",1);
//			wrapper.orderByAsc("sort");
//			List<BizReceiverPerson> personAll = this.bizReceiverPersonService.list(wrapper);
//			if(personAll!=null&&personAll.isEmpty()){
//				map.put("longitude", personAll.get(0).getLongitude());
//				map.put("latitude", personAll.get(0).getLatitude());
//				QueryWrapper<BizReceiverGoods> goods = new QueryWrapper<>();
//				goods.eq("receiverid", personAll.get(0).getPersonId());
//				map.put("goods", this.bizReceiverGoodsService.list(goods));
//				map.put("address",personAll.get(0).getLocation()+" "+personAll.get(0).getAddrdetail());
//				map.put("phone", personAll.get(0).getReceiverPhone());
//				map.put("name", personAll.get(0).getReceiverName());
//			}
//		}*/
//		return FunctionUtils.getSuccessRest("前往出发",map);
//	}
//
//}
